<?php
class TaskModel extends Model{
	protected $Id;
	protected $SheetId;
	protected $Number;
	protected $Desc;
	protected $Button;
	protected $ChBox;
	protected $Attach;
	protected $Score;

	function SetId($id){
		return $this->Id=$id;
	}
	
	function SetSheetId($sheetid){
		return $this->SheetId=$sheetid;
	}
	
	function SetNumber($number){
		return $this->Number=$number;
	}

	function SetDesc($desc){
		return $this->Desc=$desc;
	}
	
	function SetButton($button){
		return $this->Button=$button;
	}
	
	function SetChBox($chbox){
		return $this->ChBox=$chbox;
	}
	
	function SetAttach($attach){
		return $this->Attach=$attach;
	}
	
	function SetScore($score){
		return $this->Score=$score;
	}
	
	function GetId(){
		return $this->Id;
	}
	
	function GetSheetId(){
		return $this->SheetId;
	}
	
	function GetNumber(){
		return $this->Number;
	}
	
	function GetDesc(){
		return $this->Desc;
	}
	
	function GetButton(){
		return $this->Button;
	}
	
	function GetChBox(){
		return $this->ChBox;
	}
	
	function GetAttach(){
		return $this->Attach;
	}
	
	function GetScore(){
		return $this->Score;
	}
	
	
	function Validate(){
		$errors =  array();
		if((strlen($this->Desc)) == 0 ){
			//Alarm BOX!!!!!!!
			$errors[] = "Task name is empty";
		}
		return $errors;
	}
	
	function InsertTaskToSql(){
		$error = $this->Validate();
		if(count($error) > 0 ){
			return $error;    
		}
		else{
			$stmt = $this->db->sqldb->prepare("INSERT INTO task (sheet_id, number, description, is_button, is_checkbox, attachment, score) VALUES (:sheet_id, :number, :description, :is_button, :is_checkbox, :attachment, :score)");
			$stmt->bindParam(':sheet_id', $this->SheetId);
			$stmt->bindParam(':number', $this->Number);
			$stmt->bindParam(':description', $this->Desc);
			$stmt->bindParam(':is_button', $this->Button);
			$stmt->bindParam(':is_checkbox', $this->ChBox);
			$stmt->bindParam(':attachment', $this->Attach);
			$stmt->bindParam(':score', $this->Score);
			$stmt->execute();
			$arr = array();
			$arr = $stmt->errorInfo();
			return $arr;
		}
	}
	
	function SelectTaskFromSql($id){
		$temp = $this->db->query("SELECT * FROM task WHERE id= ?", array($id), $fetch = FALSE, $bindType = TRUE);
		$this->Id = $temp[0]['id'];
		$this->SheetId = $temp[0]['sheet_id'];
		$this->Number = $temp[0]['number'];
		$this->Desc = $temp[0]['description'];
		$this->Button = $temp[0]['is_button'];
		$this->ChBox = $temp[0]['is_checkbox'];
		$this->Attach = $temp[0]['attachment'];
		$this->Score = $temp[0]['score'];
	}
	
	function SelectAllTaskFromSql($sheet_id){
		$temp = $this->db->query("SELECT * FROM task WHERE sheet_id= ?", array($sheet_id), $fetch = FALSE, $bindType = TRUE);
		return $temp;
	}
	
	/*function UpdateTaskSheetInSql(){
		$temp = $this->db->query('UPDATE task SET name=?, date=?, expire=? WHERE id= ?', array($this->Name, $this->Date, $this->Expire, $this->Id), $fetch = FALSE, $bindType = TRUE);
	}*/
	
	
}	
//áéáéá
?>